package tote.services;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;

import org.springframework.context.ApplicationContext;

import tote.context.AppContext;
import tote.model.Team;

public class TeamConverter implements Converter {
    protected ApplicationContext ctx = AppContext.getApplicationContext();

    @Override
    public Object getAsObject(FacesContext arg0, UIComponent arg1, String teamid) {
	UserService us = (UserService) ctx.getBean("userService");
	return us.findTeamById(Integer.parseInt(teamid));
    }

    @Override
    public String getAsString(FacesContext arg0, UIComponent arg1, Object team) {
	return "" + ((Team) team).getTeamid();
    }

}
